//模仿Extjs底层继承函数的实现(Ext.extend())
Ext.onReady(function() {

	function Person(name) {
		this.name = name;
	}
	
	//继承父类的模版代码
	function Boy(name, sex, age) {
		Person.call(this, name);
		this.sex = sex;
		this.age = age;
	}
	
	/**
	 * 继承函数
	 * 用于继承父类的原型，如果不这么写，那么有一下几种替代方法:
	 * a) Boy.prototype = new Person();
	 * 弊端就是又继承了一遍模版代码，两遍了
	 * b) Boy.prototype = Person.prototype;
	 * 这样的缺点就是如果你修改constructor属性:Boy.prototype.constructor = Boy;
	 * 那么Person.prototype.constructor也是Boy了，这不完蛋了
	 */
	function extend(subclass, superclass) {
		//中转函数
		var F = function() {};
		F.prototype = superclass.prototype;
		subclass.prototype = new F();
		subclass.prototype.constructor = subclass;
		if (subclass.prototype.constructor === Object.prototype.constructor) {
			subclass.prototype.constructor = subclass;
		}
	}
	
	extend(Boy, Person);
	
	var boy = new Boy("skywalker", "男", 22);
	alert(boy.name + " " + boy.sex + " " + boy.age);
	
});

//利用Extjs实现继承
Ext.define("Person", {
	config: {
		name: "default"
	},
	constructor: function(config) {
		this.initConfig(config);
	}
});

//定义子类
Ext.define("Boy", {
	//关键就在于这个属性
	extend: "Person",
	config: {
		sex: "未定义",
		age: 20
	}
});

var boy = Ext.create("Boy", {
	name: "skywalker",
	sex: "男",
	age: 22
});
alert(boy.getName() + " " + boy.getSex() + " " + boy.getAge());